package com.lu.adog.demo.main.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.lu.adog.R;
import com.lu.adog.demo.base.BaseConfig;
import com.lu.adog.demo.common.CommonTask;
import com.lu.adog.demo.common.adapter.CommonAdapter;
import com.lu.adog.demo.main.MainListActivity;
import com.lu.adog.demo.main.page.image.HandleImageFragment;
import com.lu.adog.demo.main.data.model.ItemModel;
import com.lu.adog.demo.main.page.view.ViewFragment;

import java.util.List;

/**
 * @author Yue
 * @date 2017/11/15 17:34
 */

public class MainListAdapter extends CommonAdapter {

    private MainListActivity mainView;

    public MainListAdapter(Context context, MainListActivity mainView) {
        super(context);
        this.mainView = mainView;
    }

    @Override
    protected void initItemModeArray(Context context, List<ItemModel> itemModelList) {
        int[] names = {R.string.view_name, R.string.handle_image_name};
        int[] des = {R.string.view_des, R.string.handle_image_des};
        new CommonTask().genItemModelList(itemModelList, names, des);
    }

    @Override
    protected void onItemModelClick(View view, int position, int itemNameStrId) {
        switch (itemNameStrId) {
            case R.string.view_name:
                setPage(new ViewFragment(),R.string.view_name);
                break;
            case R.string.handle_image_name:
//                visitActivity(HandleImageListActivity.class,R.string.handle_image_name);
                setPage(new HandleImageFragment(),R.string.handle_image_name);
                break;
        }
    }
    private void setPage(Fragment fragment,int title){
        Bundle bundle = fragment.getArguments();
        if (bundle == null){
            bundle = new Bundle();
        }
        bundle.putInt(BaseConfig.KEY_TITLE,title);
        fragment.setArguments(bundle);
        mainView.setContentPage(fragment);
    }
}
